package com.gtt.jr.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gtt.jr.constants.Status;
import com.gtt.jr.repository.ContainerDao;
import com.gtt.jr.repository.domain.Container;

/**
 * 集装箱服务实现
 * 
 * @author 高甜甜(gao12581@sina.com)
 * @date 2010-9-4
 * 
 */
@Service("containerService")
public class ContainerServiceImpl implements ContainerService {

	@Resource
	private ContainerDao containerDao;

	public List<Container> findByType(Long typeId) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("select c");
		sql.append(" from Container c, ContainerTypeBridge cb");
		sql.append(" where c.id=cb.container.id");
		sql.append(" and cb.containerType.id=? ");
		sql.append(" and c.status=? ");
		return containerDao.find(Container.class, sql.toString(), new Object[] {
				typeId, Status.NORMAL });
	}

	public void save(Container container) {
		containerDao.save(container);
	}

	public Container load(Long id) {
		return containerDao.load(id);
	}

}
